package org.example;

import java.util.HashMap;
import java.util.Map;

// 记录类Student有两个字段：name和age，它们都是private final类型
record Student (String name, int age, String className) {}

public class Main {
    public static void main(String[] args) {
        Student student = new Student("John", 18, "082班");
        System.out.println(student); // Student[name=John, age=18]

        // record类的访问器和JavaBean不同，访问器的名称就是字段名
        System.out.println(student.name());
        System.out.println(student.age());
        System.out.println(student.className());

        Student student1 = new Student("San", 18, "081班");

        // record类可以作为Map的key使用
        Map<Student, String> map = new HashMap<>();
        map.put(student, "John");
        map.put(student1, "San");

        String value = map.get(new Student("San", 18, "081班"));
        System.out.println(value); // San
    }
}